<?php

namespace app\Admin\controller;

//引入公共控制器
use app\common\controller\Backend;

use think\Db;
/**
 * 图表
 */
class Analysis extends Backend
{   
    public function __construct()
    {
        parent::__construct();

        $this->CateModel = model('Post.Cate');
        $this->PostModel = model('Post.Post');

    }

    public function post()
    {
        $catelist = $this->CateModel->field('id,name')->order('id DESC')->select();

        //array_column()抽取出二维数组中指定字段的内容变成一个新数组
        $row = array_column($catelist, 'name'); 

        foreach($catelist as $item)
        {
        
            // 已结
            $where = [
                'accept' => ['exp', Db::raw("is not null")],
                'cateid' => $item['id']
            ];
            $AcceptList[] =  $this->PostModel->where($where)->count();
        
            // 未结
            $whres = [
                'accept' => ['exp', Db::raw("is null")],
                'cateid' => $item['id']
            ];
            $NotAcceptList[] = $this->PostModel->where($whres)->count();
     
        
        }
        $this->assign([
            //转换为json
            'catelist' => json_encode($row),
            'AcceptList' => json_encode($AcceptList),
            'NotAcceptList' => json_encode($NotAcceptList),
        ]);

        return $this->fetch();
    }
}